package com.ins1st.plus.config.shiro;

import org.apache.shiro.web.session.mgt.DefaultWebSessionManager;
import org.crazycake.shiro.RedisCacheManager;
import org.crazycake.shiro.RedisManager;
import org.crazycake.shiro.RedisSessionDAO;
import org.springframework.context.annotation.Bean;

/**
 * @program: ins1st-plus
 * @description: shiro redis 存储配置
 * @author: coderSun
 * @create: 2019-09-09 13:24
 **/
public class ShiroRedisConfig {

    public RedisCacheManager cacheManager(String host, int port, String password) {
        RedisCacheManager redisCacheManager = new RedisCacheManager();
        redisCacheManager.setRedisManager(redisManager(host, port, password));
        return redisCacheManager;
    }


    public RedisManager redisManager(String host, int port, String password) {
        RedisManager redisManager = new RedisManager();
        redisManager.setHost(host + ":" + port);
        redisManager.setPassword(password);
        return redisManager;
    }

    @Bean
    public DefaultWebSessionManager sessionManager(String host, int port, String password) {
        DefaultWebSessionManager sessionManager = new DefaultWebSessionManager();
        sessionManager.setSessionDAO(redisSessionDAO(host, port, password));
        return sessionManager;
    }


    @Bean
    public RedisSessionDAO redisSessionDAO(String host, int port, String password) {
        RedisSessionDAO redisSessionDAO = new RedisSessionDAO();
        redisSessionDAO.setRedisManager(redisManager(host, port, password));
        return redisSessionDAO;
    }
}
